/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BussinessObject;

import DataAccessObject.*;
import java.sql.ResultSet;

/**
 *
 * @author ngoctoan
 */
public class DanhmucBO {

    public ResultSet LayTatCaDuLieu() {
        try {
            SQLServerDAO dao = new SQLServerDAO();
            ResultSet rs = dao.LayDuLieu("SELECT * FROM tblDanhmuc");
            return rs;
        } catch (Exception e) {
            System.out.println(e);
        }
        return null;
    }

    public ResultSet TimKiemDanhMuc(String tuKhoa) {
        try {
            SQLServerDAO dao = new SQLServerDAO();
            ResultSet rs = dao.LayDuLieu("SELECT * FROM tblDanhmuc WHERE Madm LIKE N'%" + tuKhoa + "%' OR Tendm LIKE N'%" + tuKhoa + "%' OR Mota LIKE N'%" + tuKhoa + "%'");
            return rs;
        } catch (Exception e) {
            System.out.println(e);
        }
        return null;
    }

    public int ThemDanhmuc(Object Madm, Object Tendm, Object Mota) {
        try {
            SQLServerDAO dao = new SQLServerDAO();
            Object p[] = new Object[3];
            //System.out.println(row+1);

            p[0] = Madm;
            p[1] = Tendm;
            p[2] = Mota;
            System.out.println(p[1]);
            int kq = dao.UpdateQuery("INSERT INTO tblDanhmuc VALUES(?,?,?)", p);
            return kq;
        } catch (Exception e) {
            System.out.println("1" + e);
        }
        return 0;
    }

    public int SuaDanhMuc(Object ID_Danhmuc, Object Madm, Object Tendm, Object Mota) {
        try {
            SQLServerDAO dao = new SQLServerDAO();
            Object p[] = new Object[4];

            p[0] = Madm;
            p[1] = Tendm;
            p[2] = Mota;
            p[3] = ID_Danhmuc;

            int kq = dao.UpdateQuery("UPDATE tblDanhmuc SET Madm = ?, Tendm = ?, Mota = ? WHERE ID_Danhmuc = ?", p);
            return kq;
        } catch (Exception e) {
            System.out.println("1" + e);
        }
        return 0;
    }

    public int XoaDanhMuc(Object ID_Danhmuc) {
        try {
            SQLServerDAO dao = new SQLServerDAO();
            Object p[] = new Object[1];
            p[0] = ID_Danhmuc;

            int kq = dao.UpdateQuery("DELETE FROM tblDanhmuc WHERE ID_Danhmuc = ?", p);
            return kq;
        } catch (Exception e) {
            System.out.println("1" + e);
        }
        return 0;
    }
}
